import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

# 生成数据
val = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(val)
y = r * np.cos(val)

# 初始化图形
(line,) = ax.plot(x, y, z, "r")


# 动画函数
def update(frame):
    ax.view_init(elev=10, azim=frame)
    return line


ani = FuncAnimation(fig, update, frames=np.arange(0, 360, 1), interval=50, blit=False)
plt.show()
